package com.hongning.railway.ui.main.mine.score;

import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hongning.railway.BR;
import com.hongning.railway.R;
import com.hongning.railway.app.AppViewModelFactory;
import com.hongning.railway.app.Constant;
import com.hongning.railway.databinding.FragmentMainscoreBinding;
import com.hongning.railway.entity.resbean.ResScoreRankInfo;

import me.goldze.mvvmhabit.base.BaseFragment;

public class MainScoreFragment extends BaseFragment<FragmentMainscoreBinding, MainScoreFragmentViewModel> {
    private ResScoreRankInfo resScoreRankInfo;
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_mainscore;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initParam() {
        super.initParam();
        if (getArguments()!=null){
            resScoreRankInfo = getArguments().getParcelable(Constant.EXTRA_DATA);
        }
    }

    @Override
    public void initData() {
        super.initData();
        binding.appTitle.ivLeft.setVisibility(View.VISIBLE);
        binding.appTitle.ivLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        binding.appTitle.tvTopTitle.setText("积分排名");
        viewModel.initViewData();
        if (resScoreRankInfo!=null){
            viewModel.score.set(String.valueOf(resScoreRankInfo.getSumScore()));
            viewModel.hnscore.set(String.valueOf(resScoreRankInfo.getHNScore()));
            viewModel.socore_sub.set(String.valueOf(resScoreRankInfo.getStrongCountryScore()));
        }
        viewModel.setmResScoreRankInfo(resScoreRankInfo);
    }

    @Override
    public MainScoreFragmentViewModel initViewModel() {
        AppViewModelFactory appViewModelFactory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this,appViewModelFactory).get(MainScoreFragmentViewModel.class);
    }
}
